package com.kwshare.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kwshare.common.core.domain.system.RoleMenu;
import com.kwshare.system.mapper.RoleMenuMapper;
import com.kwshare.system.service.IRoleMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户角色接口
 *
 * @author yangjing
 */
@Service
public class RoleMenuServiceImpl implements IRoleMenuService {

    @Resource
    private RoleMenuMapper roleMenuMapper;

    @Override
    public int updateRoleMenu(Long roleId, List<Long> ids) {
        QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id",roleId);
        queryWrapper.ge("menu_id",100);
        roleMenuMapper.delete(queryWrapper);
        for(Long menuId : ids){
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setRoleId(roleId);
            roleMenu.setMenuId(menuId);
            roleMenuMapper.insert(roleMenu);
        }
        return 1;
    }
}
